| 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{
|
|
|
30 |
Order oneOrder = orders.get(0);
|
|
|
31 |
Party consignee = getConsigneeParty(oneOrder);
|
|
|
32 |
Shipment shp = getShipment(new ShipmentInfo(orders), consignee, getTestShipper());
|
|
|
33 |
return getAwb(shp);
|
| 20640 |
amit.gupta |
34 |
}
|
| 20642 |
amit.gupta |
35 |
|
|
|
36 |
private Shipment getShipment(ShipmentInfo shipmentInfo, Party consignee, Party shipper) {
|
|
|
37 |
Shipment shp = new Shipment();
|
|
|
38 |
ShipmentDetails details = new ShipmentDetails();
|
|
|
39 |
details.setProductGroup("DOM");
|
|
|
40 |
details.setProductType("CDA");
|
|
|
41 |
details.setPaymentType("P");
|
|
|
42 |
details.setChargeableWeight(new Weight("KG", shipmentInfo.getTotalWeightInKg()));
|
|
|
43 |
details.setDescriptionOfGoods("Electronics");
|
|
|
44 |
details.setGoodsOriginCountry("IN");
|
|
|
45 |
if(shipmentInfo.getOrder().isLogisticsCod()){
|
|
|
46 |
details.setServices("CODS");
|
|
|
47 |
details.setCashOnDeliveryAmount(new Money("INR", shipmentInfo.getTotalAmount() + shipmentInfo.getTotalShippingAmount()));
|
|
|
48 |
}
|
|
|
49 |
details.setCustomsValueAmount(new Money("INR", shipmentInfo.getTotalAmount()));
|
|
|
50 |
details.setNumberOfPieces(shipmentInfo.getTotalPcs());
|
|
|
51 |
|
|
|
52 |
shp.setDetails(details);
|
|
|
53 |
shp.setShipper(shipper);
|
|
|
54 |
shp.setConsignee(consignee);
|
|
|
55 |
shp.setPickupLocation("Gurgaon");
|
|
|
56 |
shp.setShippingDateTime(Calendar.getInstance());
|
|
|
57 |
Calendar dueDate = Calendar.getInstance();
|
|
|
58 |
dueDate.add(Calendar.DATE, 4);
|
|
|
59 |
shp.setDueDate(dueDate);
|
|
|
60 |
|
|
|
61 |
return shp;
|
|
|
62 |
}
|
| 20640 |
amit.gupta |
63 |
|
| 20642 |
amit.gupta |
64 |
private Party getConsigneeParty(Order order) {
|
|
|
65 |
Party consignee = new Party();
|
|
|
66 |
|
|
|
67 |
Address consigneeAddress = new Address();
|
|
|
68 |
consigneeAddress.setCountryCode("IN");
|
|
|
69 |
consigneeAddress.setLine1(order.getCustomer_address1());
|
|
|
70 |
consigneeAddress.setLine2(order.getCustomer_address2());
|
|
|
71 |
consigneeAddress.setPostCode(order.getCustomer_pincode());
|
|
|
72 |
consigneeAddress.setStateOrProvinceCode(order.getCustomer_state());
|
|
|
73 |
consigneeAddress.setCity(order.getCustomer_city());
|
|
|
74 |
|
|
|
75 |
Contact contact = new Contact();
|
|
|
76 |
contact.setCellPhone(order.getCustomer_mobilenumber());
|
|
|
77 |
contact.setPersonName(order.getCustomer_name());
|
|
|
78 |
contact.setEmailAddress(order.getCustomer_email());
|
|
|
79 |
|
|
|
80 |
consignee.setPartyAddress(consigneeAddress);
|
|
|
81 |
consignee.setContact(contact);
|
|
|
82 |
|
|
|
83 |
return consignee;
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
private String getAwb(Shipment shipment) throws Exception{
|
|
|
87 |
Service_1_0_Service aramexService = new Service_1_0_ServiceLocator();
|
|
|
88 |
Service_1_0_PortType service = aramexService.getBasicHttpBinding_Service_1_0();
|
|
|
89 |
ShipmentCreationRequest parameters = new ShipmentCreationRequest();
|
|
|
90 |
ArrayOfShipment shipments = new ArrayOfShipment();
|
|
|
91 |
Shipment [] shipArray = new Shipment[1];
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
shipArray[0]=shipment;
|
|
|
95 |
shipments.setShipment(shipArray);
|
|
|
96 |
|
|
|
97 |
LabelInfo labelInfo = new LabelInfo();
|
|
|
98 |
labelInfo.setReportID(9729);
|
|
|
99 |
labelInfo.setReportType("URL");
|
|
|
100 |
parameters.setLabelInfo(labelInfo);
|
|
|
101 |
parameters.setClientInfo(getTestClientInfo());
|
|
|
102 |
parameters.setShipments(shipments);
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
ShipmentCreationResponse scr = service.createShipments(parameters);
|
|
|
106 |
if(scr.getHasErrors() && (scr.getNotifications() == null ||scr.getShipments().getProcessedShipment(0)==null)) {
|
|
|
107 |
System.out.println("Some error " + scr.getNotifications().getNotification());
|
|
|
108 |
throw new Exception();
|
|
|
109 |
}
|
|
|
110 |
ProcessedShipment ps = scr.getShipments().getProcessedShipment(0);
|
|
|
111 |
return ps.getID();
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
private static ClientInfo getTestClientInfo() {
|
|
|
115 |
ClientInfo clientInfo = new ClientInfo();
|
|
|
116 |
clientInfo.setAccountCountryCode("IN");
|
|
|
117 |
clientInfo.setAccountNumber("DELTST002");
|
|
|
118 |
clientInfo.setVersion("v1.0");
|
|
|
119 |
clientInfo.setAccountEntity("DEL");
|
|
|
120 |
clientInfo.setUserName("testingapi@aramex.com");
|
|
|
121 |
clientInfo.setPassword("R123456789$r");
|
|
|
122 |
clientInfo.setAccountPin("231164");
|
|
|
123 |
return clientInfo;
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
private Party getTestShipper() {
|
|
|
127 |
Party shipper = new Party();
|
|
|
128 |
shipper.setAccountNumber("DELTST002");
|
|
|
129 |
Contact sc = new Contact();
|
|
|
130 |
sc.setEmailAddress("testingapi@aramex.com");
|
|
|
131 |
sc.setCellPhone("9990381569");
|
|
|
132 |
sc.setCompanyName("TEST");
|
|
|
133 |
sc.setPersonName("Test");
|
|
|
134 |
sc.setPhoneNumber1("1234567890");
|
|
|
135 |
shipper.setContact(sc);
|
|
|
136 |
Address shipperAddress = new Address();
|
|
|
137 |
shipperAddress.setLine1("Test");
|
|
|
138 |
shipperAddress.setCity("Ggn");
|
|
|
139 |
shipperAddress.setCountryCode("IN");
|
|
|
140 |
shipperAddress.setPostCode("110001");
|
|
|
141 |
shipper.setPartyAddress(shipperAddress);
|
|
|
142 |
return shipper;
|
|
|
143 |
}
|
|
|
144 |
|
| 20640 |
amit.gupta |
145 |
}
|