-
Notifications
You must be signed in to change notification settings - Fork 3
/
calculateRequestBuilder.go
136 lines (101 loc) · 3.25 KB
/
calculateRequestBuilder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package dpd
import (
"time"
)
//NewCity creates new pointer to CityRequest
//use by CalculateRequest
func NewCity(cityID int64) *CityRequest {
return &CityRequest{
CityID: &cityID,
}
}
//SetIndex set zip code of city
func (c *CityRequest) SetIndex(index string) *CityRequest {
c.Index = &index
return c
}
//SetCityName set city name for city request
func (c *CityRequest) SetCityName(name string) *CityRequest {
c.CityName = &name
return c
}
//SetRegionCode set region code for city request
func (c *CityRequest) SetRegionCode(code int) *CityRequest {
c.RegionCode = &code
return c
}
//SetCountryCode the code must comply with ISO 3166-1 alpha-2
//If omitted, default RU
func (c *CityRequest) SetCountryCode(code string) *CityRequest {
c.CountryCode = &code
return c
}
//NewCalculateRequest creates new pointer to CalculateRequest with required parameters
func NewCalculateRequest(from, to *CityRequest, weight float64, selfPickup, selfDelivery bool) *CalculateRequest {
req := new(CalculateRequest)
req.Pickup = from
req.Delivery = to
req.Weight = &weight
req.SelfPickup = &selfPickup
req.SelfDelivery = &selfDelivery
return req
}
//OverrideFrom overrides pickup (city-sender) field in CalculateRequest struct
func (r *CalculateRequest) OverrideFrom(city *CityRequest) *CalculateRequest {
r.Pickup = city
return r
}
//OverrideTo overrides delivery (city-recipient) field in CalculateRequest struct
func (r *CalculateRequest) OverrideTo(city *CityRequest) *CalculateRequest {
r.Delivery = city
return r
}
//SetWeight set weight of parcel
func (r *CalculateRequest) SetWeight(weight float64) *CalculateRequest {
r.Weight = &weight
return r
}
//SetVolume set volume of parcel
func (r *CalculateRequest) SetVolume(volume float64) *CalculateRequest {
r.Volume = &volume
return r
}
//SetServiceCode set service codes - list of comma-separated values
//If set, DPD service will return cost only for given service codes
func (r *CalculateRequest) SetServiceCode(code string) *CalculateRequest {
r.ServiceCode = &code
return r
}
//SetPickupDate set date of parcel pickup& If not set DPD use current date by default
func (r *CalculateRequest) SetPickupDate(time time.Time) *CalculateRequest {
d := time.Format("2006-01-02")
r.PickupDate = &d
return r
}
//SetMaxDays If specific service is set up for request, call of this function with any parameter
//has not affect result of request
func (r *CalculateRequest) SetMaxDays(days int) *CalculateRequest {
r.MaxDays = &days
return r
}
//SetMaxCost If specific service is set up for request, call of this function with any parameter
//has not affect result of request
func (r *CalculateRequest) SetMaxCost(cost float64) *CalculateRequest {
r.MaxCost = &cost
return r
}
//SetDeclaredValue set cargo declared value
func (r *CalculateRequest) SetDeclaredValue(declaredValue float64) *CalculateRequest {
r.DeclaredValue = &declaredValue
return r
}
//SetSelfPickup set client-side delivery to DPD terminal
func (r *CalculateRequest) SetSelfPickup(flag bool) *CalculateRequest {
r.SelfPickup = &flag
return r
}
//SetSelfDelivery set DPD-side delivery to their terminal and customer-side pickup on DPD terminal
func (r *CalculateRequest) SetSelfDelivery(flag bool) *CalculateRequest {
r.SelfDelivery = &flag
return r
}