Subversion Repositories SmartDukaan

Rev

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