| 20640 |
amit.gupta |
1 |
package com.aramex.impl;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.model.v1.order.Order;
|
|
|
4 |
|
| 20642 |
amit.gupta |
5 |
import java.util.Calendar;
|
| 20640 |
amit.gupta |
6 |
import java.util.List;
|
|
|
7 |
|
| 20642 |
amit.gupta |
8 |
import com.aramex.stub.Address;
|
|
|
9 |
import com.aramex.stub.ArrayOfShipment;
|
|
|
10 |
import com.aramex.stub.ClientInfo;
|
|
|
11 |
import com.aramex.stub.Contact;
|
|
|
12 |
import com.aramex.stub.LabelInfo;
|
|
|
13 |
import com.aramex.stub.Money;
|
|
|
14 |
import com.aramex.stub.Party;
|
|
|
15 |
import com.aramex.stub.ProcessedShipment;
|
|
|
16 |
import com.aramex.stub.Service_1_0_PortType;
|
|
|
17 |
import com.aramex.stub.Service_1_0_Service;
|
|
|
18 |
import com.aramex.stub.Service_1_0_ServiceLocator;
|
|
|
19 |
import com.aramex.stub.Shipment;
|
|
|
20 |
import com.aramex.stub.ShipmentCreationRequest;
|
|
|
21 |
import com.aramex.stub.ShipmentCreationResponse;
|
|
|
22 |
import com.aramex.stub.ShipmentDetails;
|
|
|
23 |
import com.aramex.stub.Weight;
|
| 20640 |
amit.gupta |
24 |
import com.providers.logistics.Provider;
|
| 20642 |
amit.gupta |
25 |
import com.providers.logistics.ShipmentInfo;
|
| 20640 |
amit.gupta |
26 |
|
|
|
27 |
public class Aramex implements Provider {
|
|
|
28 |
|
| 20642 |
amit.gupta |
29 |
public String getAirwayBillNo(List<Order> orders) throws Exception{
|
| 20649 |
amit.gupta |
30 |
try {
|
|
|
31 |
Order oneOrder = orders.get(0);
|
|
|
32 |
Party consignee = getConsigneeParty(oneOrder);
|
|
|
33 |
Shipment shp = getShipment(new ShipmentInfo(orders), consignee, getTestShipper());
|
|
|
34 |
return getAwb(shp);
|
|
|
35 |
} catch (Exception e) {
|
|
|
36 |
e.printStackTrace();
|
|
|
37 |
throw e;
|
|
|
38 |
}
|
| 20640 |
amit.gupta |
39 |
}
|
| 20642 |
amit.gupta |
40 |
|
|
|
41 |
private Shipment getShipment(ShipmentInfo shipmentInfo, Party consignee, Party shipper) {
|
|
|
42 |
Shipment shp = new Shipment();
|
|
|
43 |
ShipmentDetails details = new ShipmentDetails();
|
|
|
44 |
details.setProductGroup("DOM");
|
|
|
45 |
details.setProductType("CDA");
|
|
|
46 |
details.setPaymentType("P");
|
|
|
47 |
details.setChargeableWeight(new Weight("KG", shipmentInfo.getTotalWeightInKg()));
|
| 20650 |
amit.gupta |
48 |
details.setActualWeight(new Weight("KG", shipmentInfo.getTotalWeightInKg()));
|
| 20642 |
amit.gupta |
49 |
details.setDescriptionOfGoods("Electronics");
|
|
|
50 |
details.setGoodsOriginCountry("IN");
|
|
|
51 |
if(shipmentInfo.getOrder().isLogisticsCod()){
|
|
|
52 |
details.setServices("CODS");
|
|
|
53 |
details.setCashOnDeliveryAmount(new Money("INR", shipmentInfo.getTotalAmount() + shipmentInfo.getTotalShippingAmount()));
|
|
|
54 |
}
|
|
|
55 |
details.setCustomsValueAmount(new Money("INR", shipmentInfo.getTotalAmount()));
|
|
|
56 |
details.setNumberOfPieces(shipmentInfo.getTotalPcs());
|
|
|
57 |
|
|
|
58 |
shp.setDetails(details);
|
|
|
59 |
shp.setShipper(shipper);
|
|
|
60 |
shp.setConsignee(consignee);
|
|
|
61 |
shp.setPickupLocation("Gurgaon");
|
|
|
62 |
shp.setShippingDateTime(Calendar.getInstance());
|
|
|
63 |
Calendar dueDate = Calendar.getInstance();
|
|
|
64 |
dueDate.add(Calendar.DATE, 4);
|
|
|
65 |
shp.setDueDate(dueDate);
|
|
|
66 |
|
|
|
67 |
return shp;
|
|
|
68 |
}
|
| 20640 |
amit.gupta |
69 |
|
| 20642 |
amit.gupta |
70 |
private Party getConsigneeParty(Order order) {
|
|
|
71 |
Party consignee = new Party();
|
|
|
72 |
|
|
|
73 |
Address consigneeAddress = new Address();
|
|
|
74 |
consigneeAddress.setCountryCode("IN");
|
|
|
75 |
consigneeAddress.setLine1(order.getCustomer_address1());
|
|
|
76 |
consigneeAddress.setLine2(order.getCustomer_address2());
|
|
|
77 |
consigneeAddress.setPostCode(order.getCustomer_pincode());
|
|
|
78 |
consigneeAddress.setStateOrProvinceCode(order.getCustomer_state());
|
|
|
79 |
consigneeAddress.setCity(order.getCustomer_city());
|
| 20650 |
amit.gupta |
80 |
|
| 20642 |
amit.gupta |
81 |
Contact contact = new Contact();
|
| 20650 |
amit.gupta |
82 |
contact.setPhoneNumber1(order.getCustomer_mobilenumber());
|
| 20642 |
amit.gupta |
83 |
contact.setCellPhone(order.getCustomer_mobilenumber());
|
|
|
84 |
contact.setPersonName(order.getCustomer_name());
|
|
|
85 |
contact.setEmailAddress(order.getCustomer_email());
|
| 20650 |
amit.gupta |
86 |
contact.setCompanyName(order.getCustomer_name());
|
| 20642 |
amit.gupta |
87 |
|
|
|
88 |
consignee.setPartyAddress(consigneeAddress);
|
|
|
89 |
consignee.setContact(contact);
|
|
|
90 |
|
|
|
91 |
return consignee;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
private String getAwb(Shipment shipment) throws Exception{
|
|
|
95 |
Service_1_0_Service aramexService = new Service_1_0_ServiceLocator();
|
|
|
96 |
Service_1_0_PortType service = aramexService.getBasicHttpBinding_Service_1_0();
|
|
|
97 |
ShipmentCreationRequest parameters = new ShipmentCreationRequest();
|
|
|
98 |
ArrayOfShipment shipments = new ArrayOfShipment();
|
|
|
99 |
Shipment [] shipArray = new Shipment[1];
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
shipArray[0]=shipment;
|
|
|
103 |
shipments.setShipment(shipArray);
|
|
|
104 |
|
|
|
105 |
LabelInfo labelInfo = new LabelInfo();
|
|
|
106 |
labelInfo.setReportID(9729);
|
|
|
107 |
labelInfo.setReportType("URL");
|
|
|
108 |
parameters.setLabelInfo(labelInfo);
|
| 20665 |
amit.gupta |
109 |
parameters.setClientInfo(getLiveClientInfo());
|
| 20642 |
amit.gupta |
110 |
parameters.setShipments(shipments);
|
|
|
111 |
|
|
|
112 |
|
|
|
113 |
ShipmentCreationResponse scr = service.createShipments(parameters);
|
| 20650 |
amit.gupta |
114 |
if(scr.getHasErrors()){
|
|
|
115 |
if(scr.getNotifications() != null && scr.getNotifications().getNotification() != null){
|
|
|
116 |
System.out.println("Some error " + scr.getNotifications().getNotification(0).getMessage());
|
|
|
117 |
}
|
|
|
118 |
ProcessedShipment s = scr.getShipments().getProcessedShipment(0);
|
|
|
119 |
if (s!=null && s.getNotifications() != null && s.getNotifications().getNotification() != null) {
|
|
|
120 |
System.out.println("Some error in shipment" + s.getNotifications().getNotification(0).getMessage());
|
|
|
121 |
}
|
| 20642 |
amit.gupta |
122 |
throw new Exception();
|
|
|
123 |
}
|
|
|
124 |
ProcessedShipment ps = scr.getShipments().getProcessedShipment(0);
|
|
|
125 |
return ps.getID();
|
|
|
126 |
}
|
|
|
127 |
|
| 20665 |
amit.gupta |
128 |
private static ClientInfo getLiveClientInfo() {
|
| 20642 |
amit.gupta |
129 |
ClientInfo clientInfo = new ClientInfo();
|
|
|
130 |
clientInfo.setAccountCountryCode("IN");
|
| 20665 |
amit.gupta |
131 |
clientInfo.setAccountNumber("50615758");
|
| 20642 |
amit.gupta |
132 |
clientInfo.setVersion("v1.0");
|
|
|
133 |
clientInfo.setAccountEntity("DEL");
|
| 20665 |
amit.gupta |
134 |
clientInfo.setUserName("adonismobitrade@yahoo.com");
|
|
|
135 |
clientInfo.setPassword("Adonis@12345");
|
|
|
136 |
clientInfo.setAccountPin("321321");
|
| 20642 |
amit.gupta |
137 |
return clientInfo;
|
|
|
138 |
}
|
|
|
139 |
|
| 20665 |
amit.gupta |
140 |
/*private static ClientInfo getTestClientInfo() {
|
|
|
141 |
ClientInfo clientInfo = new ClientInfo();
|
|
|
142 |
clientInfo.setAccountCountryCode("IN");
|
|
|
143 |
clientInfo.setAccountNumber("50615758");
|
|
|
144 |
clientInfo.setVersion("v1.0");
|
|
|
145 |
clientInfo.setAccountEntity("DEL");
|
|
|
146 |
clientInfo.setUserName("adonismobitrade@yahoo.com");
|
|
|
147 |
clientInfo.setPassword("Adonis@12345");
|
|
|
148 |
clientInfo.setAccountPin("231164");
|
|
|
149 |
return clientInfo;
|
|
|
150 |
}*/
|
|
|
151 |
|
| 20642 |
amit.gupta |
152 |
private Party getTestShipper() {
|
|
|
153 |
Party shipper = new Party();
|
| 20665 |
amit.gupta |
154 |
shipper.setAccountNumber("50615758");
|
| 20642 |
amit.gupta |
155 |
Contact sc = new Contact();
|
| 20665 |
amit.gupta |
156 |
sc.setEmailAddress("adonismobitrade@yahoo.com");
|
|
|
157 |
sc.setCellPhone("9311608716");
|
|
|
158 |
sc.setCompanyName("Adonis Mobitrade Pvt Ltd");
|
|
|
159 |
sc.setPersonName("Deenanath Gupta");
|
|
|
160 |
sc.setPhoneNumber1("9311608716");
|
| 20642 |
amit.gupta |
161 |
shipper.setContact(sc);
|
|
|
162 |
Address shipperAddress = new Address();
|
| 20665 |
amit.gupta |
163 |
shipperAddress.setLine1("Plot No. 485, Udyog Vihar Phase V");
|
|
|
164 |
shipperAddress.setCity("Gurgoan");
|
| 20642 |
amit.gupta |
165 |
shipperAddress.setCountryCode("IN");
|
| 20665 |
amit.gupta |
166 |
shipperAddress.setPostCode("122016");
|
| 20642 |
amit.gupta |
167 |
shipper.setPartyAddress(shipperAddress);
|
|
|
168 |
return shipper;
|
|
|
169 |
}
|
| 20650 |
amit.gupta |
170 |
|
| 20640 |
amit.gupta |
171 |
}
|