means that
the end of one possibility may create room for another, so a setback need not mean the end of one's prospects.
also
When a door shuts, a window opens.
Imagine a case where someone should not loose hope when an opportunity or a favourable situation finishes, because always a new opportunity can be found .; then “When one door shuts, another opens” fits well.