Subversion Repositories SmartDukaan

Rev

Rev 20649 | Rev 20665 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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