you are already calculate distance in your CTE, so why are you calculate it again in your select statement next to CTE, just use it from CTE like this...
WITH CTE AS (
SELECT
rownum = ROW_NUMBER() OVER (ORDER BY di.recno ),
si.ShipmentNo as ManiFest,
t.TruckNo,
j.Route,
j.Ordernumber as Invoice,
w.Name,di.Latitude as dLatitude ,di.Longitude as dLongitude,di.DeliveryDate,
di.DeliveryTime ,w.Latitude ,w.Longitude ,'' as DistanceBy,
dbo.Distance(w.Latitude ,w.Longitude, di.Latitude ,di.Longitude) as Distance
from tbl_pms_DeliveryInfo di
Inner Join tbl_pms_JobOrders j on j.JobID = di.JobID
Inner Join tbl_pms_JobOrders_Trucks_Info jt on jt.JobID = j.JobID
Inner Join tbl_pms_Trucks t on t.TruckID = jt.TruckID
Inner Join tbl_pms_Warehouses w on w.WarehouseID = j.WarehouseID
Inner Join tbl_pms_ShipmentInfo si on si.ShipmentID = jt.ShipmentID
where t.TruckID != 312 and
t.TruckNo = 'WFN 2976' and j.Planneddate between '20131003' and '20140103'
)
SELECT
CTE.Route
, COUNT(distinct CTE.ManiFest)as TotalManiFest
, COUNT(CTE.Invoice) as TotalInvoice
, CTE.TruckNo
, CTE.Name
, CTE.DeliveryDate
, CTE.Distance as DISTANCEWH
FROM CTE
LEFT JOIN CTE prev ON prev.rownum = CTE.rownum - 1
LEFT JOIN CTE nex ON nex.rownum = CTE.rownum + 1
GROUP BY
CTE.Route
, CTE.TruckNo
, CTE.Name
, CTE.DeliveryDate
, CTE.Distance