2

I've been searching the web and reading through the FedEx Web Services Developer Guide to see if its possible to use their API to submit a couple ZIP codes and return an estimated transit time for a Ground package. Similar to what FedEx's "Get Rates & Transit Times" page does. Has anyone done something like this?

ampsy
  • 23
  • 6

1 Answers1

1

In order to do this you need to use FedEx's "Validation Availability and Commitment Service". Here is a link to their PDF on its use: https://www.fedex.com/templates/components/apps/wpor/secure/downloads/pdf/201607/FedEx_WebServices_ValidationAvailabilityAndCommitmentServices_WSDLGuide_v2016.pdf

I have also been working on it and have put together a quick and dirty little piece of PHP code that works.

<?php

  // This is the local path to the FedEx Validation Availability and Commitment Service WSDL
  $_wsdlPath = '/xxxxxx/xxxxx/xxxxx/ValidationAvailabilityAndCommitmentService_v6.wsdl'; 

  $ship_from_zip = 10001;
  $ship_to_zip = 90210;

  // Create the SOAP client
  try {
    $client = new SoapClient($_wsdlPath, array('trace' => 1));
  }
  catch(SoapFault $soapFault) {
    print($soapFault);
    return;
  }

  // Create our request that we will send to FedEx
  $transit_time_request = createTransitTimeRequest($ship_from_zip, $ship_to_zip);

  // Send our request to FedEx
  $transit_time_response = callTransitTimeRequest($client, $transit_time_request);

  print_r($transit_time_response);

  function callTransitTimeRequest($client, $transit_time_request) {
    try {
      // Call FedEx's serviceAvailability operation
      $response = $client->serviceAvailability($transit_time_request);
      return $response;
    }
    catch(SoapFault $soapFault) {
      print($soapFault);
      return null;
    }
  }

  function createTransitTimeRequest($ship_from_zip, $ship_to_zip) {
    $_meterNumber = 'xxxxxx'; // Your accounts ClientDetail MeterNumber
    $_accountNumber = 'xxxxx'; // You accounts ClientDetail AccountNumber
    $_password = 'xxxxxx'; // Your accounts UserCredential Password
    $_key = 'xxxxx'; // Your accounts UserCredential Key
    $_majorVersion = X; // The WSDL version

    $request['WebAuthenticationDetail'] = array();
    $request['WebAuthenticationDetail']['UserCredential'] = array();
    $request['WebAuthenticationDetail']['UserCredential']['Key'] = $_key;
    $request['WebAuthenticationDetail']['UserCredential']['Password'] = $_password;
    $request['ClientDetail'] = array();
    $request['ClientDetail']['AccountNumber'] = $_accountNumber;
    $request['ClientDetail']['MeterNumber'] = $_meterNumber;
    $request['TransactionDetail'] = array();
    $request['TransactionDetail']['CustomerTransactionId'] = 'ServiceAvailabilityRequest';
    $request['Version'] = array();
    $request['Version']['ServiceId'] = 'vacs';
    $request['Version']['Major'] = $_majorVersion;
    $request['Version']['Intermediate'] = '0';
    $request['Version']['Minor'] = '0';
    $request['Origin'] = array();
    $request['Origin']['PostalCode'] = $ship_from_zip;
    $request['Origin']['CountryCode'] = 'US';
    $request['Destination'] = array();
    $request['Destination']['PostalCode'] = $ship_to_zip;
    $request['Destination']['CountryCode'] = 'US';
    $request['ShipDate'] = date("Y-m-d");
    $request['CarrierCode'] = "FDXG"; // FDXG = Ground, FDXE = Express

    return $request;
  }

?>

Also, this is what the above code returns and what you can expect:

stdClass Object
(
    [HighestSeverity] => NOTE
    [Notifications] => stdClass Object
        (
            [Severity] => NOTE
            [Source] => vacs
            [Code] => 2002
            [Message] => Your Packaging was assumed.
            [LocalizedMessage] => Your Packaging was assumed.
        )

    [TransactionDetail] => stdClass Object
        (
            [CustomerTransactionId] => ServiceAvailabilityRequest
        )

    [Version] => stdClass Object
        (
            [ServiceId] => vacs
            [Major] => 6
            [Intermediate] => 0
            [Minor] => 0
        )

    [Options] => Array
        (
            [0] => stdClass Object
                (
                    [Service] => FEDEX_GROUND
                    [TransitTime] => FOUR_DAYS
                )

            [1] => stdClass Object
                (
                    [Service] => GROUND_HOME_DELIVERY
                    [TransitTime] => FOUR_DAYS
                )

        )

)
fr0x
  • 196
  • 1
  • 5