Subversion Repositories SmartDukaan

Rev

Rev 8353 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7930 manish.sha 1
package in.shop2020.serving.services;
2
 
3
import in.shop2020.config.ConfigException;
4
import in.shop2020.serving.model.ShipmentUpdate;
5
import in.shop2020.thrift.clients.config.ConfigClient;
6
 
7
import java.text.SimpleDateFormat;
8
import java.util.ArrayList;
9
import java.util.List;
10
import com.TrackWebServiceClient;
11
import com.fedex.track.stub.ClientDetail;
12
import com.fedex.track.stub.TrackDetail;
13
import com.fedex.track.stub.TrackEvent;
14
import com.fedex.track.stub.TrackReply;
15
import com.fedex.track.stub.WebAuthenticationCredential;
16
import com.fedex.track.stub.WebAuthenticationDetail;
17
 
18
public class FedExTrackingService {
19
 
20
	private TrackReply trackreply;
21
	/**
22
	 * @param args
23
	 */
24
 
25
	public List<ShipmentUpdate> getUpdates(String awbNumber){
26
		List<ShipmentUpdate> updates = new ArrayList<ShipmentUpdate>();
27
		 ClientDetail clientDetail = new ClientDetail();
28
	        String accountNumber ="";
29
	        String meterNumber ="";
30
			try {
31
				accountNumber = ConfigClient.getClient().get("fedex_account_number");
32
				meterNumber = ConfigClient.getClient().get("fedex_meter_number");
33
			} catch (ConfigException e) {
34
				e.printStackTrace();
35
			}			
36
	        clientDetail.setAccountNumber(accountNumber);
37
	        clientDetail.setMeterNumber(meterNumber);
38
	        WebAuthenticationCredential wac = new WebAuthenticationCredential();
39
	        String key="";
40
	        String password="";
41
			try {
42
				key = ConfigClient.getClient().get("fedex_authenication_key");
43
				password = ConfigClient.getClient().get("fedex_authenication_password");
44
			} catch (ConfigException e) {
45
				e.printStackTrace();
46
			}
47
	        wac.setKey(key);
48
	        wac.setPassword(password);
49
         String endPoint="";
50
			try {
51
				endPoint = ConfigClient.getClient().get("fedex_endpoint_address_track");
52
			} catch (ConfigException e) {
53
				e.printStackTrace();
54
			}
55
 
56
		trackreply = TrackWebServiceClient.getTrackingUpdates(awbNumber, clientDetail, new WebAuthenticationDetail(wac), endPoint);
57
		if(trackreply!=null){
58
			TrackDetail[] trackDetails=trackreply.getTrackDetails();
59
			SimpleDateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
60
			SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
61
			for (int i=0; i< trackDetails.length; i++) {
62
				TrackEvent trackEvents[]= trackDetails[i].getEvents();
63
				for(TrackEvent te : trackEvents){
64
					ShipmentUpdate shipUpdate = new ShipmentUpdate();
65
					shipUpdate.city= te.getAddress().getCity();
66
					shipUpdate.date= dateformat.format(te.getTimestamp().getTime());
67
					shipUpdate.time= timeformat.format(te.getTimestamp().getTime());
68
					shipUpdate.description= te.getEventDescription();
69
					updates.add(shipUpdate);
70
				}			
71
			}
72
			return updates;
73
		}
74
		else{
75
			return null;
76
		}
77
	}
78
 
79
	public static void main(String[] args) {
80
		FedExTrackingService trackClient = new FedExTrackingService();
81
		List<ShipmentUpdate> updates = trackClient.getUpdates("59104178545");
82
		for(ShipmentUpdate update: updates){
83
			System.out.println(update.toString());
84
		}
85
	}
86
 
87
}