| 20640 |
amit.gupta |
1 |
package com.aramex.impl;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.model.v1.order.Order;
|
|
|
4 |
|
| 20960 |
kshitij.so |
5 |
import java.util.ArrayList;
|
| 20642 |
amit.gupta |
6 |
import java.util.Calendar;
|
| 22577 |
amit.gupta |
7 |
import java.util.Date;
|
| 20640 |
amit.gupta |
8 |
import java.util.List;
|
|
|
9 |
|
| 20642 |
amit.gupta |
10 |
import com.aramex.stub.Address;
|
|
|
11 |
import com.aramex.stub.ArrayOfShipment;
|
|
|
12 |
import com.aramex.stub.ClientInfo;
|
|
|
13 |
import com.aramex.stub.Contact;
|
|
|
14 |
import com.aramex.stub.LabelInfo;
|
|
|
15 |
import com.aramex.stub.Money;
|
|
|
16 |
import com.aramex.stub.Party;
|
|
|
17 |
import com.aramex.stub.ProcessedShipment;
|
|
|
18 |
import com.aramex.stub.Service_1_0_PortType;
|
|
|
19 |
import com.aramex.stub.Service_1_0_Service;
|
|
|
20 |
import com.aramex.stub.Service_1_0_ServiceLocator;
|
|
|
21 |
import com.aramex.stub.Shipment;
|
|
|
22 |
import com.aramex.stub.ShipmentCreationRequest;
|
|
|
23 |
import com.aramex.stub.ShipmentCreationResponse;
|
|
|
24 |
import com.aramex.stub.ShipmentDetails;
|
|
|
25 |
import com.aramex.stub.Weight;
|
| 20640 |
amit.gupta |
26 |
import com.providers.logistics.Provider;
|
| 20642 |
amit.gupta |
27 |
import com.providers.logistics.ShipmentInfo;
|
| 20640 |
amit.gupta |
28 |
|
|
|
29 |
public class Aramex implements Provider {
|
|
|
30 |
|
| 20642 |
amit.gupta |
31 |
public String getAirwayBillNo(List<Order> orders) throws Exception{
|
| 21904 |
amit.gupta |
32 |
//return String.valueOf(new Date().getTime());
|
|
|
33 |
try {
|
| 20649 |
amit.gupta |
34 |
Order oneOrder = orders.get(0);
|
|
|
35 |
Party consignee = getConsigneeParty(oneOrder);
|
| 20666 |
amit.gupta |
36 |
Party shipper = getTestShipper();
|
|
|
37 |
shipper.setReference1(oneOrder.getLogisticsTransactionId());
|
|
|
38 |
Shipment shp = getShipment(new ShipmentInfo(orders), consignee, shipper);
|
| 22185 |
amit.gupta |
39 |
shp.setThirdParty(getThirdParty());
|
| 20649 |
amit.gupta |
40 |
return getAwb(shp);
|
|
|
41 |
} catch (Exception e) {
|
|
|
42 |
e.printStackTrace();
|
|
|
43 |
throw e;
|
| 21904 |
amit.gupta |
44 |
}
|
| 20640 |
amit.gupta |
45 |
}
|
| 20642 |
amit.gupta |
46 |
|
|
|
47 |
private Shipment getShipment(ShipmentInfo shipmentInfo, Party consignee, Party shipper) {
|
|
|
48 |
Shipment shp = new Shipment();
|
|
|
49 |
ShipmentDetails details = new ShipmentDetails();
|
|
|
50 |
details.setProductGroup("DOM");
|
|
|
51 |
details.setProductType("CDA");
|
| 22185 |
amit.gupta |
52 |
//For thirdParty
|
|
|
53 |
details.setPaymentType("3");
|
|
|
54 |
//details.setPaymentType("P");
|
| 20642 |
amit.gupta |
55 |
details.setChargeableWeight(new Weight("KG", shipmentInfo.getTotalWeightInKg()));
|
| 20650 |
amit.gupta |
56 |
details.setActualWeight(new Weight("KG", shipmentInfo.getTotalWeightInKg()));
|
| 20642 |
amit.gupta |
57 |
details.setDescriptionOfGoods("Electronics");
|
|
|
58 |
details.setGoodsOriginCountry("IN");
|
| 20960 |
kshitij.so |
59 |
if(shipmentInfo.isCashOnDelivery()){
|
| 20642 |
amit.gupta |
60 |
details.setServices("CODS");
|
| 20938 |
amit.gupta |
61 |
details.setCashOnDeliveryAmount(new Money("INR", shipmentInfo.getNetPayable()));
|
| 20642 |
amit.gupta |
62 |
}
|
|
|
63 |
details.setCustomsValueAmount(new Money("INR", shipmentInfo.getTotalAmount()));
|
|
|
64 |
details.setNumberOfPieces(shipmentInfo.getTotalPcs());
|
|
|
65 |
|
|
|
66 |
shp.setDetails(details);
|
|
|
67 |
shp.setShipper(shipper);
|
|
|
68 |
shp.setConsignee(consignee);
|
| 22185 |
amit.gupta |
69 |
shp.setPickupLocation("Delhi");
|
| 20642 |
amit.gupta |
70 |
shp.setShippingDateTime(Calendar.getInstance());
|
|
|
71 |
Calendar dueDate = Calendar.getInstance();
|
|
|
72 |
dueDate.add(Calendar.DATE, 4);
|
|
|
73 |
shp.setDueDate(dueDate);
|
|
|
74 |
|
|
|
75 |
return shp;
|
|
|
76 |
}
|
| 20640 |
amit.gupta |
77 |
|
| 20642 |
amit.gupta |
78 |
private Party getConsigneeParty(Order order) {
|
|
|
79 |
Party consignee = new Party();
|
|
|
80 |
|
|
|
81 |
Address consigneeAddress = new Address();
|
|
|
82 |
consigneeAddress.setCountryCode("IN");
|
|
|
83 |
consigneeAddress.setLine1(order.getCustomer_address1());
|
|
|
84 |
consigneeAddress.setLine2(order.getCustomer_address2());
|
|
|
85 |
consigneeAddress.setPostCode(order.getCustomer_pincode());
|
|
|
86 |
consigneeAddress.setStateOrProvinceCode(order.getCustomer_state());
|
|
|
87 |
consigneeAddress.setCity(order.getCustomer_city());
|
| 20650 |
amit.gupta |
88 |
|
| 20642 |
amit.gupta |
89 |
Contact contact = new Contact();
|
| 20650 |
amit.gupta |
90 |
contact.setPhoneNumber1(order.getCustomer_mobilenumber());
|
| 20642 |
amit.gupta |
91 |
contact.setCellPhone(order.getCustomer_mobilenumber());
|
|
|
92 |
contact.setPersonName(order.getCustomer_name());
|
|
|
93 |
contact.setEmailAddress(order.getCustomer_email());
|
| 20650 |
amit.gupta |
94 |
contact.setCompanyName(order.getCustomer_name());
|
| 20642 |
amit.gupta |
95 |
|
|
|
96 |
consignee.setPartyAddress(consigneeAddress);
|
|
|
97 |
consignee.setContact(contact);
|
|
|
98 |
|
|
|
99 |
return consignee;
|
|
|
100 |
}
|
|
|
101 |
|
| 22185 |
amit.gupta |
102 |
private Party getThirdParty() {
|
|
|
103 |
Party thirdParty = new Party();
|
|
|
104 |
|
|
|
105 |
thirdParty.setAccountNumber("IDA10002");
|
|
|
106 |
|
|
|
107 |
Address thirdPartyAddress = new Address();
|
|
|
108 |
thirdPartyAddress.setCountryCode("IN");
|
|
|
109 |
thirdPartyAddress.setLine1("S Global Knowledge Park");
|
|
|
110 |
thirdPartyAddress.setLine2("19A & 19B, Sector-125");
|
|
|
111 |
thirdPartyAddress.setPostCode("201301");
|
|
|
112 |
thirdPartyAddress.setStateOrProvinceCode("Uttar Pradesh");
|
|
|
113 |
thirdPartyAddress.setCity("Noida");
|
|
|
114 |
|
|
|
115 |
Contact sc = new Contact();
|
|
|
116 |
sc.setEmailAddress("deena.nath@profitmandi.com");
|
|
|
117 |
sc.setCellPhone("9311608716");
|
|
|
118 |
sc.setCompanyName("New Spice Solutions Private Limited");
|
|
|
119 |
sc.setPersonName("Deenanath Gupta");
|
|
|
120 |
sc.setPhoneNumber1("9311608716");
|
|
|
121 |
|
|
|
122 |
thirdParty.setPartyAddress(thirdPartyAddress);
|
|
|
123 |
thirdParty.setContact(sc);
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
return thirdParty;
|
|
|
127 |
}
|
|
|
128 |
|
| 20642 |
amit.gupta |
129 |
private String getAwb(Shipment shipment) throws Exception{
|
|
|
130 |
Service_1_0_Service aramexService = new Service_1_0_ServiceLocator();
|
|
|
131 |
Service_1_0_PortType service = aramexService.getBasicHttpBinding_Service_1_0();
|
|
|
132 |
ShipmentCreationRequest parameters = new ShipmentCreationRequest();
|
|
|
133 |
ArrayOfShipment shipments = new ArrayOfShipment();
|
|
|
134 |
Shipment [] shipArray = new Shipment[1];
|
|
|
135 |
|
|
|
136 |
|
|
|
137 |
shipArray[0]=shipment;
|
|
|
138 |
shipments.setShipment(shipArray);
|
|
|
139 |
|
|
|
140 |
LabelInfo labelInfo = new LabelInfo();
|
|
|
141 |
labelInfo.setReportID(9729);
|
|
|
142 |
labelInfo.setReportType("URL");
|
|
|
143 |
parameters.setLabelInfo(labelInfo);
|
| 20665 |
amit.gupta |
144 |
parameters.setClientInfo(getLiveClientInfo());
|
| 22598 |
amit.gupta |
145 |
parameters.setShipments(shipArray);
|
| 20642 |
amit.gupta |
146 |
|
| 22577 |
amit.gupta |
147 |
System.out.println(parameters);
|
| 20642 |
amit.gupta |
148 |
ShipmentCreationResponse scr = service.createShipments(parameters);
|
| 20650 |
amit.gupta |
149 |
if(scr.getHasErrors()){
|
| 22598 |
amit.gupta |
150 |
if(scr.getNotifications() != null && scr.getNotifications()[0]!= null){
|
|
|
151 |
System.out.println("Some error " + scr.getNotifications()[0].getMessage());
|
| 20650 |
amit.gupta |
152 |
}
|
| 22598 |
amit.gupta |
153 |
ProcessedShipment s = scr.getShipments()[0];
|
|
|
154 |
if (s!=null && s.getNotifications() != null && s.getNotifications()[0] != null) {
|
|
|
155 |
System.out.println("Some error in shipment" + s.getNotifications()[0].getMessage());
|
| 20650 |
amit.gupta |
156 |
}
|
| 20642 |
amit.gupta |
157 |
throw new Exception();
|
|
|
158 |
}
|
| 22598 |
amit.gupta |
159 |
ProcessedShipment ps = scr.getShipments()[0];
|
| 20642 |
amit.gupta |
160 |
return ps.getID();
|
|
|
161 |
}
|
|
|
162 |
|
| 20665 |
amit.gupta |
163 |
private static ClientInfo getLiveClientInfo() {
|
| 20642 |
amit.gupta |
164 |
ClientInfo clientInfo = new ClientInfo();
|
|
|
165 |
clientInfo.setAccountCountryCode("IN");
|
| 22029 |
amit.gupta |
166 |
clientInfo.setAccountNumber("IDA10002");
|
| 20642 |
amit.gupta |
167 |
clientInfo.setVersion("v1.0");
|
| 22185 |
amit.gupta |
168 |
clientInfo.setAccountEntity("IDA");
|
| 22029 |
amit.gupta |
169 |
clientInfo.setUserName("deena.nath@profitmandi.com");
|
|
|
170 |
clientInfo.setPassword("Profitmandi@123");
|
|
|
171 |
clientInfo.setAccountPin("554654");
|
| 20642 |
amit.gupta |
172 |
return clientInfo;
|
|
|
173 |
}
|
|
|
174 |
|
| 20665 |
amit.gupta |
175 |
/*private static ClientInfo getTestClientInfo() {
|
|
|
176 |
ClientInfo clientInfo = new ClientInfo();
|
|
|
177 |
clientInfo.setAccountCountryCode("IN");
|
|
|
178 |
clientInfo.setAccountNumber("50615758");
|
|
|
179 |
clientInfo.setVersion("v1.0");
|
|
|
180 |
clientInfo.setAccountEntity("DEL");
|
|
|
181 |
clientInfo.setUserName("adonismobitrade@yahoo.com");
|
|
|
182 |
clientInfo.setPassword("Adonis@12345");
|
|
|
183 |
clientInfo.setAccountPin("231164");
|
|
|
184 |
return clientInfo;
|
|
|
185 |
}*/
|
|
|
186 |
|
| 20642 |
amit.gupta |
187 |
private Party getTestShipper() {
|
|
|
188 |
Party shipper = new Party();
|
|
|
189 |
Contact sc = new Contact();
|
| 22138 |
amit.gupta |
190 |
sc.setEmailAddress("deena.nath@profitmandi.com");
|
| 20665 |
amit.gupta |
191 |
sc.setCellPhone("9311608716");
|
| 22138 |
amit.gupta |
192 |
sc.setCompanyName("New Spice Solutions Private Limited");
|
| 20665 |
amit.gupta |
193 |
sc.setPersonName("Deenanath Gupta");
|
|
|
194 |
sc.setPhoneNumber1("9311608716");
|
| 20642 |
amit.gupta |
195 |
shipper.setContact(sc);
|
|
|
196 |
Address shipperAddress = new Address();
|
| 21906 |
amit.gupta |
197 |
shipperAddress.setLine1("Khasra No-322, Second Floor");
|
|
|
198 |
shipperAddress.setLine2("Opp. Purani Tel Mil, Neb Sarai");
|
| 20642 |
amit.gupta |
199 |
shipperAddress.setCountryCode("IN");
|
| 21906 |
amit.gupta |
200 |
shipperAddress.setPostCode("110068");
|
| 20642 |
amit.gupta |
201 |
shipper.setPartyAddress(shipperAddress);
|
| 22185 |
amit.gupta |
202 |
//ccountNumber("IDA10002");
|
| 20642 |
amit.gupta |
203 |
return shipper;
|
|
|
204 |
}
|
| 20650 |
amit.gupta |
205 |
|
| 20960 |
kshitij.so |
206 |
public static void main(String[] args) {
|
|
|
207 |
List<Order> orders = new ArrayList<Order>();
|
|
|
208 |
Order o = new Order();
|
|
|
209 |
o.setTotal_amount(1000.00);
|
|
|
210 |
o.setTotal_weight(.900);
|
|
|
211 |
o.setNet_payable_amount(0.01);
|
|
|
212 |
o.setShippingCost(20.0);
|
|
|
213 |
o.setCod(true);
|
|
|
214 |
orders.add(o);
|
|
|
215 |
ShipmentInfo s = new ShipmentInfo(orders);
|
|
|
216 |
System.out.println(s.isCashOnDelivery());
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
}
|
|
|
220 |
|
| 20640 |
amit.gupta |
221 |
}
|