get fedex rates from your server

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>

All ColdFusion Tutorials By Author: Ayhan
  • Mutli-Word search for best result
    We think that we have the right search function! But we don't have. Lets see I what I am trying to say. For example: You are trying to find a tutorial about javascript validation. when you search "javascript validation" results comes "0". But they have tutorial about validation and they stored it as "JavaScript Form Validation". If you want to see it at search result page you must write in order as it is in database or indexes.. let's see how we can get correct search results.
    Author: Ayhan
    Views: 15,602
    Posted Date: Monday, April 5, 2004
  • get fedex rates from your server
    If have online store or you are planning to have one; then you must give estimate or real number of shipping charge(I am only talking about FedEx). There are few ways to do this. Like using FedEx ship API writing some script(or using XML injection ) to request rates from FedEx servers. But there is big handicap; FedEx shipAPI is slowing down your application and sometimes their servers are down. Which all doesnt sound good for e-commerce business. This little code is calculating 100% accurately all kind of FedEx services. and there is no handicap because it is running from your server. The only thing you need to is you should call fedex and ask for zone list for your zip code. I have attached database file which is for my location.
    Author: Ayhan
    Views: 14,774
    Posted Date: Saturday, September 18, 2004
  • UPS XML address verification with Coldfusion
    Why need UPS address validation? Answer is; to provide time and transit information to the customers. UPS needs right City State and Zip Code to able give time and transit information. I have submitted another example which I have combined time&trasit information with rating, also tracking tutorial. You should know that this tutorial is made for my needs. If you want to expand, please visit www.ec.ups.com and download instruction. Dont afraid of size the booklet:) you will only need the request inputs and response outputs. It is easy to use. I will suggest you use cfdump to see all variables you get from ups servers. I hope these will save your hours.
    Author: Ayhan
    Views: 16,013
    Posted Date: Thursday, May 12, 2005
  • UPS XML Time&Transit+Rates with Coldfusion
    This is complete rating and Time&Transit tutorial for UPS. to use this you must provide verified address. I have added another tutorial which shows how to verify an address. You should know that this tutorial is made for my needs. If you want to expand, please visit www.ec.ups.com and download instruction. Dont afraid of size the booklet:) you will only need the request inputs and response outputs. It is easy to use. I will suggest you use cfdump to see all variables you get from ups servers.
    Author: Ayhan
    Views: 16,448
    Posted Date: Thursday, May 12, 2005
Download the EasyCFM.COM Browser Toolbar!