shipment_tracking.php
1    <?php 
2    use http\Client, http\Client\Request; 
3     
4    //set request parameters 
5    $pronumber = '164882013'; 
6    //$masterbolnumber='17737747'; 
7    $opostalcode = '40701'; 
8    $dpostalcode = '46511'; 
9     
10   if ($masterbolnumber && (!$pronumber)) { 
11       $url = "http://www.daytonfreight.com//WebServices_v1.1/TrackingService.asmx/TrackByBillOfLading?billOfLadingNumber=" 
12           . $masterbolnumber . "&originZipCode=" . $opostalcode . "&destinationZipCode=" . $dpostalcode; 
13   } else { 
14       $url = "http://www.daytonfreight.com//WebServices_v1.1/TrackingService.asmx/TrackByPro?proNumbers=" . $pronumber; 
15   } 
16    
17   try { 
18       $request = new Request("GET", $url, ["User-Agent" => "My Client/0.1"]); 
19       $client = new Client; 
20       $client->enqueue($request)->send(); 
21       $response = $client->getResponse(); 
22       $carrierresponse = $response; 
23    
24   } catch (Exception $e) { 
25       echo 'Caught exception during URL request from ' . $e->getFile() . ':' . $e->getLine() . ' - ' . $e->getMessage(); 
26       throw $e; 
27   } 
28    
29   // Parse XML text into nested objects 
30   libxml_use_internal_errors(true); 
31   $xmlobj = simplexml_load_string($response->getBody()); 
32   $statusdescription = strtoupper((string)$xmlobj->TrackingDetailedResult->Status->LastActivity); 
33   $actualpickupdate = $xmlobj->TrackingDetailedResult->PickupDate; 
34    
35   // mapping status code 
36   switch ($statusdescription) { 
37       case 'DELIVERED' : 
38           $statuscode = "DELIVERED"; 
39           $actualdeliverydate = $xmlobj->TrackingDetailedResult->Status->LastActivityDate; 
40           $deliverysignature = $xmlobj->TrackingDetailedResult->Status->SignedBy; 
41           break; 
42       case 'DELIVERED TO DESTINATION' : 
43           $statuscode = "DELIVERED"; 
44           $actualdeliverydate = $xmlobj->TrackingDetailedResult->Status->LastActivityDate; 
45           $deliverysignature = $xmlobj->TrackingDetailedResult->Status->SignedBy; 
46           break; 
47       case 'OUT FOR DELIVERY' : 
48           $statuscode = "OUTFORDELIVERY"; 
49           break; 
50       default : 
51           $statuscode = "ENROUTE"; 
52           break; 
53   } 
54   print "<h2>Tracking information</h2>"; 
55   print "Status code: $statuscode<br>"; 
56   print "Status description: $statusdescription<br>"; 
57   print "Actual pickup date: $actualpickupdate<br>"; 
58   print "Actual delivery date: $actualdeliverydate<br>"; 
59   print "Delivery signature: $deliverysignature<br>"; 
60   print "<h2>Raw Tracking object</h2>"; 
61   print "<pre>"; 
62   print_r($xmlobj); 
63   ?>