string findRoute( array stops, double HWPref, integer weight, boolean optimize)
Finds a route between specified locations.

Parameters:
stops - array of locations (any valid object with x, y, and label fields);
HWPref - highway preference (0-100);
weight - route preference (quickest or shortest);
optimize - enables or disables the optimizing route parameter (also known as the "Travelling Salesman Problem").

Returns:
Route ID string or empty string.


Function findRoute( stops, HWPref, weight, optimize)

    Dim rProblem : Set rProblem = Map.getRouting().createRoutingProblem()
    Dim rStop, i, RouteID

    For i = 0 To UBound( stops) - 1

        Set rStop = Server.CreateObject("RMIMS.RoutingStop")
        rStop.setStop createPoint( stops(i).x, stops(i).y)
        rStop.setLabel stops(i).label
        rProblem.addStop(rStop)

    Next
	
    If weight = rmQuickest Then

        rProblem.setHighwayPreference HWPref
        rProblem.setWeight rmQuickest ' find quickest route

    Else
    
        rProblem.setWeight rmShortest ' find shortest route
        
    End If

    rProblem.setOptimize optimize

    RouteID = Map.getRouting().findRoute((rProblem), false, -1)
	
    findRoute = RouteID
    
End Function

Function createPoint(x, y)

    Dim pt
    Set pt = Server.CreateObject("RMIMS.GeoPoint")

    pt.x = x
    pt.y = y

    Set createPoint = pt
	
End Function


Example:
Dim stops() : ReDim stops(4)

Set stops(0) = new GeoLocation : stops(0).init "Redlands, CA", 34.0528, -117.1531
Set stops(1) = new GeoLocation : stops(1).init "Loma Linda, CA", 34.0484, -117.2629
Set stops(2) = new GeoLocation : stops(2).init "San Bernardino, CA", 34.1214, -117.3046
Set stops(3) = new GeoLocation : stops(3).init "Highland, CA", 34.1282, -117.2106

RouteID = findRoute( stops, 50, rmShortest, false)

If RouteID <> "" Then
    showRoute(RouteID)
End If

Function showRoute( RouteID)

    Dim Routing : Set Routing = Map.getRouting()
    
    ' show the route
    Routing.setRoute RouteID
    Set r = Routing.getDrivingDirections( RouteID).getExtent()
    Map.setExtent inflateRect(r, 10) ' increase borders

    ' print driving directions
    Set DDirs = Routing.getDrivingDirections( RouteID)
    Dim DSeg
	
    Response.Write( "<p>"&DDirs.getStartText()&"<br>"&vbCrLf)
    Response.Write( DDirs.getFinishText()&"<br>"&vbCrLf)
    Response.Write( DDirs.getTotalText()&"<p>"&vbCrLf)

    For i = 0 To DDirs.getSegmentCount()-1

        Set DSeg = DDirs.getSegment( i)
        Response.Write( (i+1) & ". " & DSeg.getText()+"<br>"&vbCrLf)
        ' if there is TimeLengthText
        If DSeg.getSegmentType <> rmArrive AND _
           DSeg.getSegmentType() <> rmDepart Then 
           
            Response.Write( DSeg.getTimeLengthText()&"<br>"&vbCrLf)
            
        End If
		
    Next

End Function

Class GeoLocation

    Public label
    Public x
    Public y	

    Public Function init( ilabel, ilat, ilon)
        Set proj = Map.getProjection()
        Set pt = proj.project( ilat, ilon)
        label = ilabel
        x = pt.x
        y = pt.y
    End Function

End Class

Function inflateRect(ByRef r, percVal)

    Dim dx, dy

    dx = ((r.right - r.left) * percVal) / 100.0
    dy = ((r.top - r.bottom) * percVal) / 100.0

    r.left   = r.left   - dx
    r.top    = r.top    + dy
    r.right  = r.right  + dx
    r.bottom = r.bottom - dy

    Set inflateRect = r
	
End Function