| Line 22... |
Line 22... |
| 22 |
*/
|
22 |
*/
|
| 23 |
|
23 |
|
| 24 |
|
24 |
|
| 25 |
public class ShipWebServiceClient
|
25 |
public class ShipWebServiceClient
|
| 26 |
{
|
26 |
{
|
| - |
|
27 |
/*
|
| - |
|
28 |
fedex_account_number_mumbai=512033946
|
| - |
|
29 |
fedex_meter_number=105452205
|
| - |
|
30 |
fedex_authenication_key=ggqFObyBaF3ECQbQ
|
| - |
|
31 |
fedex_authenication_password=LIf9WMXsKqJV30AsGbK2Fy4TQ
|
| - |
|
32 |
fedex_endpoint_address_track=https://ws.fedex.com:443/web-services/track
|
| - |
|
33 |
fedex_endpoint_address_ship=https://ws.fedex.com:443/web-services/ship
|
| - |
|
34 |
*/
|
| - |
|
35 |
/*public static void main(String[] args) throws Exception {
|
| - |
|
36 |
ClientDetail clientDetail = new ClientDetail();
|
| - |
|
37 |
clientDetail.setAccountNumber("512033946");
|
| - |
|
38 |
clientDetail.setMeterNumber("106151740");
|
| - |
|
39 |
WebAuthenticationCredential wac = new WebAuthenticationCredential();
|
| - |
|
40 |
wac.setKey("DERXFRxP8qOqw0h8");
|
| - |
|
41 |
//ta0q2IFeWpPcnuEAr8pdav3PD
|
| - |
|
42 |
wac.setPassword("ta0q2IFeWpPcnuEAr8pdav3PD");
|
| - |
|
43 |
String endPointAddress = "https://ws.fedex.com:443/web-services/ship";
|
| - |
|
44 |
Order order = new TransactionClient().getClient().getOrder(554218L);
|
| - |
|
45 |
ProcessShipmentReply reply = getShipmentCreationReply(order,clientDetail, new WebAuthenticationDetail(wac), endPointAddress);
|
| - |
|
46 |
System.out.println(reply);
|
| - |
|
47 |
}*/
|
| 27 |
|
48 |
|
| 28 |
public static ProcessShipmentReply getShipmentCreationReply(Order t_order ,ClientDetail clientDetail, WebAuthenticationDetail wac, String endpointAddress){
|
49 |
public static ProcessShipmentReply getShipmentCreationReply(List<Order> orders ,ClientDetail clientDetail, WebAuthenticationDetail wac, String endpointAddress, long providerId){
|
| 29 |
ProcessShipmentRequest request = new ProcessShipmentRequest(); // Build a request object
|
50 |
ProcessShipmentRequest request = new ProcessShipmentRequest(); // Build a request object
|
| 30 |
System.out.println("Account Number... "+clientDetail.getAccountNumber());
|
51 |
System.out.println("Account Number... "+clientDetail.getAccountNumber());
|
| 31 |
System.out.println("Meter Number... "+clientDetail.getMeterNumber());
|
52 |
System.out.println("Meter Number... "+clientDetail.getMeterNumber());
|
| 32 |
request.setClientDetail(clientDetail);
|
53 |
request.setClientDetail(clientDetail);
|
| 33 |
request.setWebAuthenticationDetail(wac);
|
54 |
request.setWebAuthenticationDetail(wac);
|
| Line 39... |
Line 60... |
| 39 |
VersionId versionId = new VersionId("ship", 12, 1, 0);
|
60 |
VersionId versionId = new VersionId("ship", 12, 1, 0);
|
| 40 |
request.setVersion(versionId);
|
61 |
request.setVersion(versionId);
|
| 41 |
|
62 |
|
| 42 |
RequestedShipment requestedShipment = new RequestedShipment();
|
63 |
RequestedShipment requestedShipment = new RequestedShipment();
|
| 43 |
requestedShipment.setShipTimestamp(Calendar.getInstance());
|
64 |
requestedShipment.setShipTimestamp(Calendar.getInstance());
|
| 44 |
requestedShipment.setDropoffType(DropoffType.REGULAR_PICKUP);
|
65 |
requestedShipment.setDropoffType(DropoffType.REGULAR_PICKUP);
|
| - |
|
66 |
if(providerId==7){
|
| 45 |
requestedShipment.setServiceType(ServiceType.STANDARD_OVERNIGHT);
|
67 |
requestedShipment.setServiceType(ServiceType.STANDARD_OVERNIGHT);
|
| - |
|
68 |
}
|
| - |
|
69 |
else{
|
| - |
|
70 |
requestedShipment.setServiceType(ServiceType.FEDEX_FREIGHT_ECONOMY);
|
| - |
|
71 |
}
|
| 46 |
requestedShipment.setPackagingType(PackagingType.YOUR_PACKAGING);
|
72 |
requestedShipment.setPackagingType(PackagingType.YOUR_PACKAGING);
|
| 47 |
requestedShipment.setShipper(addShipper());
|
73 |
requestedShipment.setShipper(addShipper());
|
| 48 |
requestedShipment.setRecipient(addRecipient(t_order));
|
74 |
requestedShipment.setRecipient(addRecipient(orders.get(0)));
|
| 49 |
requestedShipment.setShippingChargesPayment(addShippingChargesPayment(clientDetail.getAccountNumber()));
|
75 |
requestedShipment.setShippingChargesPayment(addShippingChargesPayment(clientDetail.getAccountNumber()));
|
| 50 |
if(t_order.isCod()){
|
76 |
if(orders.get(0).isCod()){
|
| 51 |
requestedShipment.setSpecialServicesRequested(addShipmentSpecialServicesRequested(t_order));
|
77 |
requestedShipment.setSpecialServicesRequested(addShipmentSpecialServicesRequested(orders));
|
| 52 |
}
|
78 |
}
|
| 53 |
else{
|
79 |
else{
|
| 54 |
requestedShipment.setSpecialServicesRequested(null);
|
80 |
requestedShipment.setSpecialServicesRequested(null);
|
| 55 |
}
|
81 |
}
|
| 56 |
requestedShipment.setLabelSpecification(addLabelSpecification());
|
82 |
requestedShipment.setLabelSpecification(addLabelSpecification());
|
| 57 |
requestedShipment.setPackageCount(new NonNegativeInteger("1"));
|
83 |
requestedShipment.setPackageCount(new NonNegativeInteger("1"));
|
| 58 |
requestedShipment.setCustomsClearanceDetail(addCustomsClearanceDetail(t_order));
|
84 |
requestedShipment.setCustomsClearanceDetail(addCustomsClearanceDetail(orders));
|
| 59 |
RateRequestType rateRequestType[] = new RateRequestType[1];
|
85 |
RateRequestType rateRequestType[] = new RateRequestType[1];
|
| 60 |
rateRequestType[0] = RateRequestType.ACCOUNT;
|
86 |
rateRequestType[0] = RateRequestType.ACCOUNT;
|
| 61 |
requestedShipment.setRateRequestTypes(new RateRequestType[]{rateRequestType[0]});
|
87 |
requestedShipment.setRateRequestTypes(new RateRequestType[]{rateRequestType[0]});
|
| 62 |
requestedShipment.setRequestedPackageLineItems(new RequestedPackageLineItem[] {addRequestedPackageLineItem(t_order)});
|
88 |
requestedShipment.setRequestedPackageLineItems(new RequestedPackageLineItem[] {addRequestedPackageLineItem(orders)});
|
| 63 |
|
89 |
|
| 64 |
request.setRequestedShipment(requestedShipment);
|
90 |
request.setRequestedShipment(requestedShipment);
|
| 65 |
ProcessShipmentReply reply = new ProcessShipmentReply();
|
91 |
ProcessShipmentReply reply = new ProcessShipmentReply();
|
| 66 |
try {
|
92 |
try {
|
| 67 |
// Initialize the service
|
93 |
// Initialize the service
|
| Line 170... |
Line 196... |
| 170 |
|
196 |
|
| 171 |
|
197 |
|
| 172 |
private static Party addShipper(){
|
198 |
private static Party addShipper(){
|
| 173 |
Party shipperParty = new Party(); // Sender information
|
199 |
Party shipperParty = new Party(); // Sender information
|
| 174 |
Contact shipperContact = new Contact();
|
200 |
Contact shipperContact = new Contact();
|
| 175 |
shipperContact.setPersonName("Spice Online");
|
201 |
shipperContact.setPersonName("Spice Online Retail Pvt. Ltd.");
|
| 176 |
shipperContact.setCompanyName("Spice Online Retail Pvt Ltd");
|
202 |
shipperContact.setCompanyName("Spice Online Retail Pvt. Ltd.");
|
| 177 |
shipperContact.setPhoneNumber("01203355131");
|
203 |
shipperContact.setPhoneNumber("09811247808");
|
| 178 |
Address shipperAddress = new Address();
|
204 |
Address shipperAddress = new Address();
|
| 179 |
String address[] = new String[2];
|
205 |
String address[] = new String[2];
|
| 180 |
address[0] = new String("Plot No. 19A-19B");
|
206 |
address[0] = new String("C/O,PIBCO LIMITED,Basement,Punjsons 2");
|
| 181 |
address[1] = new String("Sector - 125");
|
207 |
address[1] = new String("Kalkaji Industrial Area");
|
| 182 |
shipperAddress.setStreetLines(address);
|
208 |
shipperAddress.setStreetLines(address);
|
| 183 |
shipperAddress.setCity("Noida");
|
209 |
shipperAddress.setCity("New Delhi");
|
| 184 |
shipperAddress.setStateOrProvinceCode("UP");
|
210 |
shipperAddress.setStateOrProvinceCode("DL");
|
| 185 |
shipperAddress.setPostalCode("201301");
|
211 |
shipperAddress.setPostalCode("110019");
|
| 186 |
shipperAddress.setCountryCode("IN");
|
212 |
shipperAddress.setCountryCode("IN");
|
| 187 |
shipperParty.setContact(shipperContact);
|
213 |
shipperParty.setContact(shipperContact);
|
| 188 |
shipperParty.setAddress(shipperAddress);
|
214 |
shipperParty.setAddress(shipperAddress);
|
| 189 |
return shipperParty;
|
215 |
return shipperParty;
|
| 190 |
}
|
216 |
}
|
| Line 246... |
Line 272... |
| 246 |
payor.setResponsibleParty(responsibleParty);
|
272 |
payor.setResponsibleParty(responsibleParty);
|
| 247 |
payment.setPayor(payor);
|
273 |
payment.setPayor(payor);
|
| 248 |
return payment;
|
274 |
return payment;
|
| 249 |
}
|
275 |
}
|
| 250 |
|
276 |
|
| 251 |
public static CustomsClearanceDetail addCustomsClearanceDetail(Order t_order){
|
277 |
public static CustomsClearanceDetail addCustomsClearanceDetail(List<Order> orders){
|
| - |
|
278 |
double totalAmount = 0;
|
| - |
|
279 |
double totalWeight = 0;
|
| - |
|
280 |
for(Order t_order: orders){
|
| - |
|
281 |
totalAmount = totalAmount + t_order.getTotal_amount();
|
| - |
|
282 |
totalWeight = totalWeight + t_order.getTotal_weight();
|
| - |
|
283 |
}
|
| 252 |
CustomsClearanceDetail detail = new CustomsClearanceDetail();
|
284 |
CustomsClearanceDetail detail = new CustomsClearanceDetail();
|
| 253 |
detail.setClearanceBrokerage(ClearanceBrokerageType.BROKER_INCLUSIVE);
|
285 |
detail.setClearanceBrokerage(ClearanceBrokerageType.BROKER_INCLUSIVE);
|
| 254 |
detail.setCustomsOptions(new CustomsOptionDetail(CustomsOptionType.TRIAL,"Trail Order"));
|
286 |
detail.setCustomsOptions(new CustomsOptionDetail(CustomsOptionType.TRIAL,"Trail Order"));
|
| 255 |
Commodity commodities[] = new Commodity[1];
|
287 |
Commodity commodities[] = new Commodity[1];
|
| 256 |
commodities[0]= new Commodity();
|
288 |
commodities[0]= new Commodity();
|
| 257 |
commodities[0].setNumberOfPieces(new NonNegativeInteger(1+""));
|
289 |
commodities[0].setNumberOfPieces(new NonNegativeInteger(1+""));
|
| 258 |
commodities[0].setDescription("Sample Commodity Data");
|
290 |
commodities[0].setDescription("Sample Commodity Data");
|
| 259 |
commodities[0].setCountryOfManufacture("India");
|
291 |
commodities[0].setCountryOfManufacture("India");
|
| 260 |
commodities[0].setQuantity(new NonNegativeInteger(1+""));
|
292 |
commodities[0].setQuantity(new NonNegativeInteger(1+""));
|
| 261 |
commodities[0].setQuantityUnits("EA");
|
293 |
commodities[0].setQuantityUnits("EA");
|
| 262 |
commodities[0].setWeight(new Weight(WeightUnits.LB,new BigDecimal(t_order.getTotal_weight())));
|
294 |
commodities[0].setWeight(new Weight(WeightUnits.LB,new BigDecimal(totalWeight)));
|
| 263 |
commodities[0].setUnitPrice(new Money("INR",new BigDecimal(t_order.getTotal_amount())));
|
295 |
commodities[0].setUnitPrice(new Money("INR",new BigDecimal(totalAmount)));
|
| 264 |
CommercialInvoice ci= new CommercialInvoice();
|
296 |
CommercialInvoice ci= new CommercialInvoice();
|
| 265 |
ci.setPurpose(PurposeOfShipmentType.SOLD);
|
297 |
ci.setPurpose(PurposeOfShipmentType.SOLD);
|
| 266 |
detail.setCommercialInvoice(ci);
|
298 |
detail.setCommercialInvoice(ci);
|
| 267 |
detail.setCommodities(commodities);
|
299 |
detail.setCommodities(commodities);
|
| - |
|
300 |
detail.setFreightOnValue(FreightOnValueType.OWN_RISK);
|
| 268 |
detail.setCustomsValue(new Money("INR",new BigDecimal(t_order.getTotal_amount())));
|
301 |
detail.setCustomsValue(new Money("INR",new BigDecimal(totalAmount)));
|
| 269 |
return detail;
|
302 |
return detail;
|
| 270 |
}
|
303 |
}
|
| 271 |
|
304 |
|
| 272 |
private static ShipmentSpecialServicesRequested addShipmentSpecialServicesRequested(Order t_order){
|
305 |
private static ShipmentSpecialServicesRequested addShipmentSpecialServicesRequested(List<Order> orders){
|
| 273 |
ShipmentSpecialServicesRequested shipmentSpecialServicesRequested = new ShipmentSpecialServicesRequested();
|
306 |
ShipmentSpecialServicesRequested shipmentSpecialServicesRequested = new ShipmentSpecialServicesRequested();
|
| 274 |
ShipmentSpecialServiceType shipmentSpecialServiceType[]=new ShipmentSpecialServiceType[1];
|
307 |
ShipmentSpecialServiceType shipmentSpecialServiceType[]=new ShipmentSpecialServiceType[1];
|
| 275 |
shipmentSpecialServiceType[0]=ShipmentSpecialServiceType.COD;
|
308 |
shipmentSpecialServiceType[0]=ShipmentSpecialServiceType.COD;
|
| 276 |
shipmentSpecialServicesRequested.setSpecialServiceTypes(shipmentSpecialServiceType);
|
309 |
shipmentSpecialServicesRequested.setSpecialServiceTypes(shipmentSpecialServiceType);
|
| 277 |
CodDetail codDetail = new CodDetail();
|
310 |
CodDetail codDetail = new CodDetail();
|
| 278 |
codDetail.setCollectionType(CodCollectionType.CASH);
|
311 |
codDetail.setCollectionType(CodCollectionType.CASH);
|
| 279 |
Money codMoney = new Money();
|
312 |
Money codMoney = new Money();
|
| 280 |
codMoney.setCurrency("INR");
|
313 |
codMoney.setCurrency("INR");
|
| - |
|
314 |
double totalAmount = 0;
|
| - |
|
315 |
for(Order t_order : orders){
|
| - |
|
316 |
totalAmount = totalAmount + t_order.getTotal_amount();
|
| - |
|
317 |
}
|
| 281 |
codMoney.setAmount(new BigDecimal(t_order.getTotal_amount()));
|
318 |
codMoney.setAmount(new BigDecimal(totalAmount));
|
| 282 |
codDetail.setCodCollectionAmount(codMoney);
|
319 |
codDetail.setCodCollectionAmount(codMoney);
|
| 283 |
shipmentSpecialServicesRequested.setCodDetail(codDetail);
|
320 |
shipmentSpecialServicesRequested.setCodDetail(codDetail);
|
| 284 |
return shipmentSpecialServicesRequested;
|
321 |
return shipmentSpecialServicesRequested;
|
| 285 |
}
|
322 |
}
|
| 286 |
|
323 |
|
| 287 |
private static RequestedPackageLineItem addRequestedPackageLineItem(Order t_order){
|
324 |
private static RequestedPackageLineItem addRequestedPackageLineItem(List<Order> orders){
|
| - |
|
325 |
double totalWeight = 0;
|
| - |
|
326 |
for(Order t_order: orders){
|
| - |
|
327 |
totalWeight = totalWeight + t_order.getTotal_weight();
|
| - |
|
328 |
}
|
| 288 |
RequestedPackageLineItem requestedPackageLineItem = new RequestedPackageLineItem();
|
329 |
RequestedPackageLineItem requestedPackageLineItem = new RequestedPackageLineItem();
|
| 289 |
requestedPackageLineItem.setSequenceNumber(new PositiveInteger("1"));
|
330 |
requestedPackageLineItem.setSequenceNumber(new PositiveInteger("1"));
|
| 290 |
requestedPackageLineItem.setGroupPackageCount(new PositiveInteger("1"));
|
331 |
requestedPackageLineItem.setGroupPackageCount(new PositiveInteger("1"));
|
| 291 |
requestedPackageLineItem.setWeight(addPackageWeight(new Double(t_order.getTotal_weight()), WeightUnits.LB));
|
332 |
requestedPackageLineItem.setWeight(addPackageWeight(new Double(totalWeight), WeightUnits.LB));
|
| 292 |
requestedPackageLineItem.setCustomerReferences(new CustomerReference[]{
|
333 |
requestedPackageLineItem.setCustomerReferences(new CustomerReference[]{
|
| 293 |
addCustomerReference(CustomerReferenceType.CUSTOMER_REFERENCE.getValue(), t_order.getCustomer_name()),
|
334 |
addCustomerReference(CustomerReferenceType.CUSTOMER_REFERENCE.getValue(), orders.get(0).getCustomer_name()),
|
| 294 |
addCustomerReference(CustomerReferenceType.INVOICE_NUMBER.getValue(), t_order.getId()+""),
|
335 |
addCustomerReference(CustomerReferenceType.INVOICE_NUMBER.getValue(), orders.get(0).getLogisticsTransactionId()+""),
|
| 295 |
addCustomerReference(CustomerReferenceType.P_O_NUMBER.getValue(), t_order.getId()+""),
|
336 |
addCustomerReference(CustomerReferenceType.P_O_NUMBER.getValue(), orders.get(0).getLogisticsTransactionId()+""),
|
| 296 |
});
|
337 |
});
|
| 297 |
return requestedPackageLineItem;
|
338 |
return requestedPackageLineItem;
|
| 298 |
}
|
339 |
}
|
| 299 |
|
340 |
|
| 300 |
private static CustomerReference addCustomerReference(String customerReferenceType, String customerReferenceValue){
|
341 |
private static CustomerReference addCustomerReference(String customerReferenceType, String customerReferenceValue){
|