Subversion Repositories SmartDukaan

Rev

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