The function getPort() returns the configured value.
Try server.getConnectors()[0].getLocalPort() it should return the selected port.
For Jetty 9:
You need to use ((ServerConnector)server.getConnectors()[0]).getLocalPort().
In both cases: you need to call server.start() first.