By: Ayhan

This tutorial includes a downloadable attachment, it is the access database that is used in this tutorial example. It can be downloaded by clicking on the link below:

Download tutorial database

<cfset dsn = "fedex">
<!-- Ground Residential Address -->
<cfset GR = 1.40>
<!-- Ground Residential Address -->
<cfset ER = 1.75>
<!-- Residental Delivery Area Surcharge -->
<cfset RS = 1.75>
<!-- Commercial Delivery Area Surcharge -->
<cfset CS = 1.00>
<!-- Ground Alaska Delivery Area Surcharge -->
<cfset GAKS = 25.00>
<!-- Ground Alaska Delivery Area Surcharge weight over 70 -->
<cfset GAKS70 = 100.00>
<!-- Express Alaska Delivery Area Surcharge -->
<cfset EAKS = 15.00>
<!-- Ground Hawaii Delivery Area Surcharge -->
<cfset GroundSurchargeHawaii = 11.00>
<!-- Express Fuel Surcharge Percentage -->
<cfset EFS = 8.5>

<cfif CGI.REQUEST_METHOD is 'post'>
    <cfquery name=
"zipzone" datasource="#dsn#">
        SELECT * 
        FROM fedexzip
        WHERE Zipcode='#form.zip#'
    </cfquery>
    <cfswitch expression=
"#form.servicetype#">
        <cfcase value=
"">
           
oppss. you must choose a shipping method
            <cfabort>
        </cfcase>
        <cfcase value=
"PO">
            <cfquery name=
"zonerates" datasource="#dsn#">
              
  SELECT * 
                FROM fedexpriority
                WHERE weight = #form.weight# 
            </cfquery>
            <cfset servicetype=
'express'>
        </cfcase>
        <cfcase value=
"SO">
            <cfquery name=
"zonerates" datasource="#dsn#">
                SELECT * 
                FROM fedexstandovnite
                WHERE weight = #form.weight# 
            </cfquery>
            <cfset servicetype=
'express'>
        </cfcase>
        <cfcase value=
"FO">
            <cfquery name=
"zonerates" datasource="#dsn#">
                SELECT * 
                FROM fedexfirstovnite
                WHERE weight = #form.weight# 
            </cfquery>
            <cfset servicetype=
'express'>
        </cfcase>
        <cfcase value=
"2DAY">
            <cfquery name=
"zonerates" datasource="#dsn#">
                SELECT * 
                FROM fedex2ndday
                WHERE weight = #form.weight# 
            </cfquery>
            <cfset servicetype=
'express'>
        </cfcase>
        <cfcase value=
"EXS">
            <cfquery name=
"zonerates" datasource="#dsn#">
                SELECT * 
                FROM fedexexpsaver
                WHERE weight = #form.weight# 
            </cfquery>
            <cfset servicetype=
'express'>
        </cfcase>
        <cfcase value=
"GRD">
            <cfquery name=
"zonerates" datasource="#dsn#">
                SELECT * 
                FROM fedexground
                WHERE weight = #form.weight# 
            </cfquery>
            <cfset servicetype=
'ground'>
        </cfcase>
    </cfswitch> 
</cfif>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv=
"Content-Type" content="text/html; charset=utf-8">
<title>
Fedex Rate Finder</title>
<style type="text/css">
    <!--
    .imp {
            font-family: Arial, Helvetica, sans-serif;
            font-size: 14px;
            background-color: #D90000;
            border: 2px solid #FF4848;
            color: #FFFFFF;
            padding-left: 5px; padding-bottom: 2px; padding-top: 2px;
        }
    -->
</style>
</head>
<cfparam name="zipzone.zone" default="">
<cfparam name=
"zonerates" default="">

<body>
<cfswitch expression="#zipzone.zone#">
    <cfcase value=
"1">
        <cfset basicrate=zonerates.zone1>
    </cfcase>
    <cfcase value=
"2">
        <cfset basicrate=zonerates.zone2>
    </cfcase>
    <cfcase value=
"3">
        <cfset basicrate=zonerates.zone3>
    </cfcase>
    <cfcase value=
"4">
        <cfset basicrate=zonerates.zone4>
    </cfcase>
    <cfcase value=
"5">
        <cfset basicrate=zonerates.zone5>
    </cfcase>
    <cfcase value=
"6">
        <cfset basicrate=zonerates.zone6>
    </cfcase>
    <cfcase value=
"7">
        <cfset basicrate=zonerates.zone7>
    </cfcase>
    <cfcase value=
"8">
        <cfset basicrate=zonerates.zone8>
    </cfcase>
    <cfcase value=
"9">
        <cfset basicrate=zonerates.zone9>
    </cfcase>
    <cfcase value=
"25">
        <cfif isdefined(
'zonerates.zone25')>
            <cfset basicrate=zonerates.zone25>
        <cfelse>
            There is no such a service to that location
            <cfabort>
        </cfif>
    </cfcase>
    <cfcase value=
"96">
        <cfset basicrate=zonerates.zone96>
    </cfcase>
</cfswitch>
<cfparam name=
"form.residential" default="no">
<cfparam name=
"form.zip" default="11229">
<cfquery name=
"das" datasource="#dsn#">
    SELECT * 
    FROM fedexdas
    WHERE Zip = #form.zip#
</cfquery>

<form action="index.cfm" method="post" name="getrate" id="getrate">
<table width="250" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#E6E6E6">
    <tr>
        <td colspan=
"2" class="imp" align="center">
        <cfoutput>
            <cfif isdefined(
'basicrate')>
                <cfif servicetype eq
'ground'>
                    <cfif form.residential eq
'yes'>
                        <cfif das.recordcount
GT 0>
                            <cfset basicrate = basicrate
+ RS>
                        </cfif>
                        <cfset basicrate = basicrate
+ GR>
                    <cfelse>
                        <cfif das.recordcount
GT 0>
                            <cfset basicrate = basicrate
+ CS>
                        </cfif>
                        <cfset basicrate = basicrate>
                    </cfif>
                    #DollarFormat(basicrate)#
                <cfelseif servicetype eq
'express'>
                    <cfif form.residential eq
'yes'>
                        <cfset basicrate = (((basicrate*EFS)/
100)+basicrate) + ER>
                        <cfif das.recordcount
GT 0>
                            <cfset basicrate = basicrate
+ RS>
                        </cfif>
                    <cfelse>
                        <cfset basicrate = (((basicrate*EFS)/
100)+basicrate)>
                        <cfif das.recordcount
GT 0>
                            <cfset basicrate = basicrate
+ CS>
                        </cfif>
                    </cfif> 
                    #DollarFormat(NumberFormat(basicrate,
'____.__'))#
                <cfelse>
                    #DollarFormat(basicrate)#
                </cfif>
            <cfelse>
               
There is no such a service to that location
            </cfif>
        </cfoutput>
        </td>
    </tr>
    <tr>
        <td>
<strong>Zip: </strong></td>
        <td>
<input name="zip" type="text" id="zip" value="<cfif isdefined('form.zip')><cfoutput>#form.zip#</cfoutput></cfif>" size="10" maxlength="5"></td>
    </tr>
    <tr>
        <td>
<strong>Weight: </strong></td>
        <td>
<input name="weight" type="text" id="weight" size="4" value="<cfif isdefined('form.weight')><cfoutput>#form.weight#</cfoutput></cfif>">
lbs</td>
    </tr>
    <tr>
        <td>
<strong>Service type: </strong></td>
        <td>

            <cfparam name="form.servicetype" default="">
            <select name=servicetype>
                <option value="">Select FedEx service</option>
                <option value=
"PO"<cfif form.servicetype is 'PO'> selected</cfif>>Priority Overnight</option>
                <option value="SO"
<cfif form.servicetype is 'SO'> selected</cfif>>Standard Overnight</option>
                <option value="FO"
<cfif form.servicetype is 'FO'> selected</cfif>>First Overnight</option>
                <option value="2DAY"
<cfif form.servicetype is '2DAY'> selected</cfif>>FedEx 2-Day</option>
                <option value="EXS"
<cfif form.servicetype is 'EXS'> selected</cfif>>FedEx Express Saver</option>
                <option value="GRD"
<cfif form.servicetype is 'GRD'> selected</cfif>>FedEx Ground</option>
            </select>
       
</td>
    </tr>
    <tr>
        <td>
&nbsp;</td>
        <td>
<label for="residential"><input name="residential" type="checkbox" id="residential"<cfif form.residential is 'yes'> checked</cfif> value="yes">
Residential</label></td>
    </tr>
    <tr>
        <td>
&nbsp;</td>
        <td>
<input type="submit" name="Submit" value="Submit"></td>
    </tr>
</table>

</form>
<cfdump var="#zipzone#">
<cfdump var=
"#zonerates#">

</body>
</html>

About This Tutorial
Author: Ayhan
Skill Level: Intermediate 
 
 
 
Platforms Tested: CFMX
Total Views: 26,717
Submission Date: September 18, 2004
Last Update Date: June 05, 2009
All Tutorials By This Autor: 4
Discuss This Tutorial
  • How do you handle it when the fedex server is down and you can't get a rate?

  • Hello Mahesh, I have most of the shipping solution.I need residential address verification part. I can assist You in other matter can You guide Me on this. Thanks, Satish

  • Hi, I am Mahesh from India. I am trying to integrate Fedex API in to our clients web application. Our clients website is an online shopping site where shipping is done by Fedex. We have to integrate Fedex Ship Manager API inorder to get complete tracking details of products. I downloaded the api software from Fedex Site and Uploaded it in to our web server which is a linux server and our website is developed in PHP. I want to get the steps to proceed. I referred the notes and documentation in Fedex site. But It doesnt provide how to send XML transactions to Fedex server using PHP and how/where to write the code for that. Also I couldnt run the aatom command in the server. So any who knows about this please reply me. I need all information from the basic as I am not an IT expert.

  • Yes I too have had problems with the FedEx API solutions. Also they have not allowed any new certified solution provider registrations in a couple of months now which leads me to believe that they are experiencing more problems with their ability to provide their API services. I agree this is a good tutorial showing how to handle these fedex shipping rates. Thank you for sharing!

  • Hi, This is first version of what I did. I didn't update it after that. I have added many option for commercial use(I can't post as tutorial). just for your information rates are changing yearly basis. only you have to update one time in a year. I think it is much much better than being depended to fedex servers. I used API for a month and their server didn't work 2 times for hours. I think this is no good for business.

  • Although this is a simple solution to some of these problems there remains numerous issues that are not addressed. There has been a custom tag in the CF community for several years now that does what you have written. I don't know if you were the original developer or not, but the custom tag (fedexmonger) and your solution fail to address some of the problems I am listing below. First I would advise letting the viewers of this tutorial know that all they have to do is go to the fedex site and download a zone chart for there given zipcode. They can also download all the other information they need in ASCII (comma seperated text file) formats for easy import into their databases. I am not trying to de-value your work as I am sure this solution will work good for most situations. But here are some issues I have came across using this and other fedex shipping solutions. Most of the solutions out there (not including the fedex api, xml solutions) only allow the rating of one weight and it's options at a time. The thought process seems to be to just total up the weights from a shopping cart or other application with the shipping options. If you have three items with weights of 20,10 and 70 lbs and just total the weights to 100 lbs. you have two or more problems already. First the rate for 100lbs is not the same as rating each weight and then summing the rates. Try it, go to fedex and rate 1 package at 100lbs, then rate three individual packages at 20,10,70 lbs. Problem two: there are limits on package weights I believe it is 70 lbs max for residential and 150 lbs for all others except freight of course. So if you total three weights to 100 lbs you loose the option to ship residential whereas if you rate the three examples above individually you would be able to ship it residential. Fedex also just recently updated their rates, so users should be sure to check the Fedex site several times yearly and import the new rates into their databases. They just posted their new calculations this month. Yes I understand that this is a simple solution and a tutorial but I feel this will only work in a one weight or Sum(weights) situation. If users shopping carts have a "cost to ship" value for each item and they want to use fedex why not just go to fedex and calculate the rates for all options per item, store them in a database then calculate it with your shopping cart solutions. Or this tutorial could be used for this, but users would have to add these rates to their databases etc. In shopping cart solutions where a customer is purchasing more than one item I feel this would not be a good solution.

Advertisement

Sponsored By...
Powered By...