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

Parameters:
map - Map object;
stops - array of locations;
HWPref - highway preference (0-100);
weight - route preference (quickest or shortest);
optimize - enables or disables the optimizing route parameter (also known as the "Traveling Salesman Problem").

Returns:
Route ID string or an empty string.


Function findRoute( map, stops, HWPref, weight, optimize)

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

    For i = 0 To UBound( stops) - 1

        rStop = new RoutingStop()
        rStop.setStop( new GeoPoint( stops(i).x, stops(i).y))
        rStop.setLabel( stops(i).label)
        rProblem.addStop(rStop)

    Next
	
    If weight = RoutingProblem.rmQuickest Then
    
        rProblem.setHighwayPreference( HWPref)
        rProblem.setWeight( RoutingProblem.rmQuickest) ' find quickest route
        
    Else
    
        rProblem.setWeight( RoutingProblem.rmShortest) ' find shortest route
        
    End If

    rProblem.setOptimize( optimize)

    RouteID = map.getRouting().findRoute((rProblem), false, -1)

    findRoute = RouteID
    
End Function

Example:

<script language="VBScript" runat=server>

    Function showRoute( ByRef map, RouteID)

        Dim Routing : Routing = map.getRouting()
        Dim DDirs, DSeg, i, r
        ' show the route
        Routing.setRoute( RouteID)
        r = Routing.getDrivingDirections( RouteID).getExtent()
        map.setExtent( inflateRect(r, 10)) ' increase borders

        ' print driving directions
        DDirs = Routing.getDrivingDirections( RouteID)
	
        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

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

            End If
		
        Next

    End Function

    Class GeoLocation

        Public label
        Public x
        Public y

        Sub New( map, ilabel, ilat, ilon)
            Dim proj, pt
            proj = map.getProjection()
            pt = proj.project( ilat, ilon)
            label = ilabel
            x = pt.x
            y = pt.y
        End Sub
    
    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

        inflateRect = r
	
    End Function

</script>

<%

    Dim map: map = OpenMap()

    Dim RouteID
    Dim stops() : ReDim stops(4)

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

    RouteID = findRoute( map, stops, 50, RoutingProblem.rmShortest, false)

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

%>

<img src="<%= map.getMapImageURL(map.getImageWidth(), map.getImageHeight(), ImageFormat.rmDefault)%>"
width="<%=map.getImageWidth()%>" height="<%=map.getImageHeight()%>">